package screen;

import resources.Assets;
import resources.Input;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;

public abstract class Game implements ApplicationListener {
	protected Screen screen;
	private Input input = new Input();
	public static int timer = 0;
	private boolean running = false;
	private float accum = 0;
	private int numScreen;
	public Assets assets;

	public void setScreen (Screen newScreen) {
		if (screen != null) screen.dispose();
		screen = newScreen;
//		if (screen != null) screen.init(this);
	}
	// phat set gia tri man hinh ngay khi khoi tao constructor
	protected void setNumSreen(int screen){
		this.numScreen = screen;
	}

//	public abstract Screen getStartScreen ();

	@Override
	public void create () {		
//		screen = getStartScreen();
		Gdx.input.setInputProcessor(input);
		//assets = new Assets();
//		Assets.load();
//		Settings.load();	
//		GameConfig.load();
	}

	@Override
	public void resume () {
		screen.resume();
	}

	@Override
	public void render () {
		if(timer>1000000) timer = 0;
		timer++;// 1 giau paint khoang 56.48 vong
//		System.out.println("timer ================================"+timer);
//		screen.update(Gdx.graphics.getDeltaTime());
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		accum += Gdx.graphics.getDeltaTime();
//		System.out.println("Gdx.graphics.getDeltaTime()================================"+Gdx.graphics.getDeltaTime());
		while (accum > 1.0f / 60.0f) {
//			System.out.println("accum ================================"+accum);
			screen.tick(input);
			input.tick(numScreen);
			accum -= 1.0f / 60.0f;
		}
		if(screen!= null )screen.present();
	}

	@Override
	public void resize (int width, int height) {

	}

	@Override
	public void pause () {
		screen.pause();
	}

	@Override
	public void dispose () {
		screen.dispose();
	}
}
